;(function($){
	$.fn.spa_init_sellte_account = function(opts,optsParams){
		var el = this;
		var opt = {
			nos:"",
			nos_checkout:"",
			togatherPrice:0,
			brzd_array : [],
			pageTh : "",	
			operation:"",		//结账类型
			xhs:"",
			dataBack : function(){},
			closeBack : function(){},
			refreshBack : function(){},
		}
		var param;
		if(typeof(opts)==="string"){ 
			optsParams=optsParams||{};
			param=$.extend({ct_brzd:[{}],ct_brxsxm:[],amount:[{}]},opt,optsParams);
		}else{
			param = $.extend(opt,opts);
			param.ct_brzd = param.data.ct_brzd[0];
			param.ct_brxsxm = param.data.ct_brxsxm;
			param.amount = param.data.amount[0];
		}
		var app = new App(el,param,opts);
	}
	var App = function(el,param,opts){
		this.el = el;
		this.param = param;
		var t = this;
		if(typeof(opts)==="string") {  
			this[opts](); 
		}else{
			this.spa_basic_info();//初始化基本信息
			this.initPosorderBill();
		}	
	};
	
	App.prototype = {
		bindEvent : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
		},
		initHtml : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
		},
		spa_basic_info : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			el.find("#ledgerHeader").empty();
			if(!$.isFunction($().spa_basic_info)){
				$.ajaxSetup({ async: false, cache: false });
	            $.getScript("js/cashier_mana/jquery.service.spa_basic_info.js");
	            $.ajaxSetup({ async: true });
			}
			el.find("#ledgerHeader").spa_basic_info({
				no : param.ct_brzd.no||"",
				th : param.ct_brzd.th||"",
				parentId:"ledgerHeader",
				position : "jsp",
				dataBack :function(ds){
					param.mno = (ds.mno||"");
				}
			});
			
			var h = 103//$("#ledgerHeader").height() 
			h = param.height - h - 5//- 65;
			var width = $(window).width();
			var hh = 82
			if(width>=1400){
				hh = 102
			}
			
			var itemHtmlInfo = "";
			var v = param.ct_brzd;
			if(v.hasOwnProperty("info")&&v.info!=""){ 
				var json=JSON.parse(v.info);
				$(json).each(function(key,value){ 
					var jsonItem=value;
					if(jsonItem.hasOwnProperty("name")){
						var bgcolor=(jsonItem.hasOwnProperty("bgcolor")?jsonItem.bgcolor:"");  
						var tcolor=(jsonItem.hasOwnProperty("tcolor")?jsonItem.tcolor:"black");    
						itemHtmlInfo+='<span class="badge" style="background:'+bgcolor+' !important;color:'+tcolor+';border-radius: 0px;font-size:15px !important">'+jsonItem.name+':'+jsonItem.value+'</span>&nbsp' 
					}
				});	
			}	
			if(itemHtmlInfo){
				hh = hh+20
			}
			
			el.find("#posorderBill").find("#billList").css("height",h-hh);
			el.find("#posorderBill").find("#connectList").css("height",h-hh);
		},
		initPosorderBill : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			//结账部分
			el.find("#tableMethodTable").empty(); 
			if(param.ct_brxsxm.length>0){
				$(param.ct_brxsxm).each(function(key,value){ 
					if(value.sort!="0") {
						var html='<tr>'+  
									'<td class="center;" style="border: 0px;">'+value.mc_c+'</td>'+  
									'<td style="text-align:right;border: 0px;">'+value.je_c+'</td>'+         
								'</tr>';
						el.find("#tableMethodTable").append(html); 
					} 
				});
				
				el.find(".total_price").text(param.amount.je);
				el.find(".pay_p").text("￥"+ param.amount.balance);
				
				t.initJzType();
//				if(!$.isFunction($().spa_jz_type)){
//					$.ajaxSetup({ async: false, cache: false });
//		            $.getScript(getContextPath()+"/static/spa/frontSpa/jquery.service.spa_jz_type.js");
//		            $.ajaxSetup({ async: true });
//				}
//				el.find("#jzBtnContent").spa_jz_type({
//					no : param.ct_brzd.no,
//					netamt : param.amount.netamt,
//					mno : param.mno||"",
//					width : param.width,
//					initDs : param.ho_dcode,
//					JSESSIONID : "",
//					grid_selector : null,
//					price : param.amount.balance,
//					togatherPrice : 0, 
//					nos : "",
//					bigType : param.payment,
//					rNum : 4,
//					lNum : 4,
//					printBillBack : function(){//打印账单
//						param.dataBack("clear");
//					},
//					dataBack : function(){
//						param.dataBack("fresh");
//					},
//					closeBack : function(){
//					},
//					getConnectInfo: function(){
//						var json = {nos:"",togatherPrice:0}
//						return json;
//					}
//				})
			}else{
				el.find(".total_price").text(0.00);
				el.find(".pay_p").text("￥"+ "0.00");
//				el.find("#jzBtnContent").find("button").hide();
				t.initJzType();
			}
		},
		initJzType : function(){
			var el = this.el;
			var param = this.param;
			var t = this;
			
			if(!$.isFunction($().spa_jz_type)){
				$.ajaxSetup({ async: false, cache: false });
	            $.getScript("js/cashier_mana/jquery.service.spa_jz_type.js");
	            $.ajaxSetup({ async: true });
			}
			el.find("#jzBtnContent").spa_jz_type({
				operation:param.operation,
				xhs:param.xhs,
				no : param.ct_brzd.no||0,
				netamt : param.amount.netamt||0,
				mno : param.mno||"",
				width : param.width,
				initDs : param.ho_dcode,
				JSESSIONID : "",
				grid_selector : null,
				price : param.amount.balance||0,
				togatherPrice :param.togatherPrice,  
				nos : param.nos,
				nos_checkout:param.nos_checkout,
				pageTh : param.pageTh,
				bigType : param.payment,
				brzd_array : param.brzd_array,
				rNum : 4,
				lNum : 4,
				bmh : param.bmh,
				printBillBack : function(){//打印账单
					param.dataBack();
				},
				dataBack : function(){
					param.dataBack();
				},
				refreshBack : function(){
					param.refreshBack();
				},
				closeBack : function(){
					param.closeBack();
				},
				getConnectInfo: function(){
					var json = {nos:param.nos,togatherPrice:param.togatherPrice,nos_checkout:param.nos_checkout} 
					return json;
				}
			})
			
		},
	}
	
	/*
	 * 私有函数
	 * 获取站点路径
	 */
	function getContextPath(){
		var pathName = document.location.pathname;
		var index = pathName.substr(1).indexOf("/");
		var path = pathName.substr(0, index + 1);
		return path;
	}
})(jQuery);